/* 2014/7/28 */
package cosmos.media;

public class ID3v2FrameHeader {
	
	public static final int TOTAL_LENGTH = 10;
	public static final int FRAME_ID_LENGTH = 4;
	public static final int SIZE_LENGTH = 4;
	public static final int FLAGS_LENGTH = 2;
	
	private byte[] frameId;
	
	private byte[] size;
	
	private byte[] flags;
	
	public ID3v2FrameHeader() {
		frameId = new byte[FRAME_ID_LENGTH];
		size = new byte[SIZE_LENGTH];
		flags = new byte[FLAGS_LENGTH];
	}
	
	public void load(byte[] bytes) {
		int i;
		int j;
		int position = 0;
		int currentIndex = 0;
		
		// Extracts frame ID.
        for (i = currentIndex, j = 0; i < currentIndex + FRAME_ID_LENGTH;
            i++, j++)
        {
            frameId[j] = bytes[i];
            position++;
        }
        currentIndex = position;

        // Extracts size.
        for (i = currentIndex, j = 0; i < currentIndex + SIZE_LENGTH;
            i++, j++)
        {
            size[j] = bytes[i];
            position++;
        }
        currentIndex = position;

        // Extracts flags.
        for (i = currentIndex, j = 0; i < currentIndex + FLAGS_LENGTH;
            i++, j++)
        {
            flags[j] = bytes[i];
            position++;
        }
        currentIndex = position;
	}
	
	public byte[] getFrameID() {
		return frameId;
	}
	
	public byte[] getSize() {
		return size;
	}
	
	public byte[] getFlags() {
		return flags;
	}
	
	public long getFrameSize() {
		long frameSize 
			= size[0] * 0x100000000L
            + size[1] * 0x10000L
            + size[2] * 0x100L
            + size[3]; 
		return frameSize;
	}
}
